﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TreeBuilder
{
	public class CombinedAction : UndoableAction
	{
		private readonly List<UndoableAction> _actions;

		public CombinedAction(IEnumerable<UndoableAction> actions)
		{
			_actions = actions.ToList();
		}

		public CombinedAction(params UndoableAction[] actions)
			:this(actions.ToList())
		{}

		public override void Execute()
		{
			foreach (var undoableAction in _actions)
			{
				undoableAction.Execute();
			}
		}

		public override void Undo()
		{
			foreach (var undoableAction in ((IEnumerable<UndoableAction>)_actions).Reverse())
			{
				undoableAction.Undo();
			}
		}
	}
}
